package com.hwua.demo03;

import com.hwua.demo01.IllegalFilePathExcepiton;
import com.hwua.util.StringTools;

import java.io.File;
import java.io.IOException;

/**
 * @author Administrator
 */
public class Demo01 {
    public static void main(String[] args) {
        Demo01 d = new Demo01();
        try {
            d.createFile("C:\\C\\C.txt");
            d.createFile("D:\\D\\D.txt");
            d.createFile("E:\\E\\E.txt");

        } catch (IllegalFilePathExcepiton illegalFilePathExcepiton) {
            illegalFilePathExcepiton.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public void createFile (String path) throws IllegalFilePathExcepiton, IOException {
        if(StringTools.checkString(path)){
           throw new IllegalFilePathExcepiton();
        }

        File file = new File(path);
        File parentFile = file.getParentFile();
        if(!parentFile.exists()){
            parentFile.mkdirs();
        }
        file.createNewFile();
    }
}
